package com.practicario.mvc.view
{	import mx.controls.Alert;
    import com.practicario.mvc.ApplicationFacade;
    
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.mediator.Mediator;
    
    public class ApplicationMediator extends Mediator implements IMediator
    {
        public static const NAME:String = "ApplicationMediator";        
        
		public function ApplicationMediator( viewComponent:Practicario ) 
        {
            super( NAME, viewComponent );            
			facade.registerMediator(new LoginMediator(app.login));
			facade.registerMediator(new PanelProfesorMediator(app.panelProfesor));
        }

        override public function listNotificationInterests():Array 
        {
            return [
						ApplicationFacade.DO_LOG_IN_SUCCESS
					];
        }

        override public function handleNotification( note:INotification ):void 
        {
            switch ( note.getName() ) 
			{
				case ApplicationFacade.DO_LOG_IN_SUCCESS:
				var tmpArray:Array = note.getBody() as Array;
				//trace(tmpArray);
				if(tmpArray[0].perfil.profile=="Profesor")
				{
					app.mainViewstack.selectedIndex = 1;
				}
				if(tmpArray[0].perfil.profile=="Alumno")
				{	
					//Alert.show("aca va alumno");
					app.mainViewstack.selectedIndex = 2;
				}
				break;
            }
        }

        protected function get app():Practicario
		{
            return viewComponent as Practicario;
        }
    }
}